<%--
  Created by IntelliJ IDEA.
  User: 姜姒
  Date: 2022/5/15
  Time: 19:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
    <script>
        layui.use(['form','laydate','layer'],function () {
            var form=layui.form,laydate=layui.laydate,layer=layui.layer;


            //自定义验证规则
            form.verify({

                account: function(value, item){
                    var min = item.getAttribute('lay-min');
                    if(value.length >= 3){
                        return '不能超过'+2+'位数';
                    }
                },
                account1: function(value, item){
                    var min = item.getAttribute('lay-min');
                    if(value.length >= 4){
                        return '不能超过'+3+'位数';
                    }
                },



                newmobile: function(value){
                    if(value.length != 3){
                        return '只能输入三位数';
                    }
                },
                chineseName: function (value) {
                    let pattern = /[\u4e00-\u9fa5]/;//中文验证
                    let txt = pattern.test(value);

                    if (value.length < 1 || !txt) {
                        return '必须要有中文';
                    }
                },
                // v_pass:[/^[\s]{1,3}$/,'长度不能超过三位数'],
                numberRequiredFalse:[/(^$)|^\d+$/,'只能填写数字'],//非必填项，填了就会进行验证
                username: function (value, item) { //value：表单的值、item：表单的DOM对象
                    if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                        return '不能有特殊字符';
                    }
                    if(/(^\_)|(\__)|(\_+$)/.test(value)){
                        return '首尾不能出现下划线\'_\'';
                    }

                }
            });

            $(function () {
                form.val('formsbt',${ss});//将对象赋给表单，自动赋值
                form.render();
            });


            form.on('submit(formBtn)',function(data){
                var formData = new FormData($("#formsbt")[0]);
                $.ajax({
                    url:'${pageContext.request.contextPath}/houqing/susheupd',
                    type : 'POST',
                    data : formData,
                    cache: false,
                    async: false,
                    processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                    contentType : false,  //必须false才会自动加上正确的Content-Type
                    success:function(data){
                        layer.msg('修改成功！',{icon:6,offset:"auto",time:2000});//提示框
                        setTimeout(function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);//关闭弹出层
                            parent.location.reload();//重新加载父页面表格
                        }, 1100);
                    }
                })
                return false;
            });

        });
    </script>
</head>
<body>
<form class="layui-form" id="formsbt" lay-filter="formsbt">

    <div class="layui-form-item">
        <input type="hidden" name="huorId">
        <label class="layui-form-label">宿舍房号:</label>
        <div class="layui-input-inline">
            <input type="text" name="huorName" class="layui-input" placaholder="宿舍房号" lay-verify="required|username|newmobile|numberRequiredFalse"/>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">宿舍地址:</label>
        <div class="layui-input-inline">
            <input type="text" name="addr" class="layui-input" placaholder="宿舍地址" lay-verify="required|username|chineseName"/>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">宿舍人数:</label>
        <div class="layui-input-inline">
            <input type="text" name="count" class="layui-input" placaholder="请输入宿舍人数" lay-verify="required|username|numberRequiredFalse|account"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">楼栋:</label>
        <div class="layui-input-inline">
            <select name="floorId">
                <c:forEach items="${sflist}" var="e">
                    <option value="${e.floorId}">${e.floorName}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">床位数:</label>
        <div class="layui-input-inline">
            <input type="text" name="numberBeds"  class="layui-input" placaholder="请输入床位" lay-verify="required|username|numberRequiredFalse|account"/>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">序号:</label>
        <div class="layui-input-inline">
            <input type="text" name="huoeIddsc"  class="layui-input" placaholder="请输入序号" lay-verify="required|username|numberRequiredFalse|account1"/>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formBtn">修改</button>
        </div>
    </div>

</form>
</body>
</html>
